/**
 * 
 */
package com.zz.datareport.service.impl;

import java.lang.reflect.InvocationTargetException;

import org.apache.commons.beanutils.BeanUtils;

import com.jfinal.plugin.activerecord.Record;
import com.zz.datareport.dao.ProjectDao;
import com.zz.datareport.schema.Project;
import com.zz.datareport.service.ProjectService;
import com.zz.datareport.test.DataObjectToJavaBean;
import com.zz.datareport.test.ProjectData;

/**
 * @author Wangys
 * @date 2018年10月7日
 */
public class ProjectServiceImpl implements ProjectService {
	private static ProjectDao projectDao = new ProjectDao();

	/**
	 * 根据id获取项目数据
	 */
	@Override
	public Project findProjectById(String id) {
		Record projectData = projectDao.findProjectById(id);
		return fillProject(projectData);
	}

	private Project fillProject(Record data) {
		DataObjectToJavaBean bean = new DataObjectToJavaBean();
		ProjectData recover = bean.recover(data, ProjectData.class);
		Project project = new Project();
		try {
			BeanUtils.copyProperties(project,recover);
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		/*if (data != null) {
			project.setPROJECTCODE(data.getStr("PROJECT_CODE"));
			project.setPROJECTNAME(data.getStr("PROJECT_NAME"));
			project.setREGIONCODE(data.getStr("REGION_CODE"));
			project.setINVESTPROJECTCODE(data.getStr("INVEST_PROJECT_CODE"));
			project.setADDRESS(data.getStr("ADDRESS"));
			project.setLEGALPERSON(data.getStr("LEGAL_PERSON"));
			project.setINDUSTRIESTYPE(data.getStr("INDUSTRIES_TYPE"));
			project.setFUNDSOURCE(data.getStr("FUND_SOURCE"));
			project.setCONTRIBUTIONSCALE(data.getStr("CONTRIBUTION_SCALE"));
			project.setPROJECTSCALE(data.getStr("PROJECT_SCALE"));
			project.setCONTACTOR(data.getStr("CONTACTOR"));
			project.setCONTACTINFORMATION(data.getStr("CONTACT_INFORMATION"));
			project.setAPPROVALNAME(data.getStr("APPROVAL_NAME"));
			project.setAPPROVALNUMBER(data.getStr("APPROVAL_NUMBER"));
			project.setAPPROVALAUTHORITY(data.getStr("APPROVAL_AUTHORITY"));
			project.setCREATETIME(data.get("CREATE_TIME").toString());
			project.setPLATFORMCODE(data.getStr("PLATFORM_CODE"));
			project.setPUBSERVICEPLATCODE(data.getStr("PUB_SERVICE_PLAT_CODE"));
			project.setDATATIMESTAMP(data.get("DATA_TIMESTAMP").toString());
		}*/
		return project;
	}

}
